package cn.lanca.esaypoi.c202204.week_4.tue;

import cn.lanca.esaypoi.util.tool.ExcelUtil;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * project name:<font size = "1"><b>小芄健康数据运营平台</b></font><br>
 * file name:<font size = "1"><b> </b></font><br>
 * description:<font size = "1"><b> </b></font><br>
 * company name:<font size = "1"><b>小芄医药科技（成都）有限公司-研发中心</b></font><br>
 *
 * @author <a href="mail to: meihongliang@xiaowanjiankang.com" rel="nofollow">meihongliang<br>
 * @version 1.0.0<br>
 * @since [1] [2022/4/26 15:53] [meihongliang] [新建] <br>
 */
public class TestAfternoon {
    public static void main(String[] args) throws IOException {

        // getDul177From1327();

    }

    private static void getDul177From1327() throws IOException {
        //
        List<CommonLess> commonLesses = ExcelUtil.readExcel("/Users/meihongliang/Downloads/A_xiaowan/download/177.xlsx", CommonLess.class);
        List<CommonMore> commonMores = ExcelUtil.readExcel("/Users/meihongliang/Downloads/A_xiaowan/download/1327.xlsx", CommonMore.class);
        System.out.println(commonLesses.size());//176
        System.out.println(commonMores.size());//1330

        // 商品名称+批准文号+规格+生产企业
        commonMores.forEach(e -> {
            e.setKey4(e.getA3() + "_" + e.getA10() + "_" + e.getA5() + "_" + e.getA16());
        });
        commonLesses.forEach(e -> {
            e.setKey4(e.getA5() + "_" + e.getA10() + "_" + e.getA7() + "_" + e.getA8());
        });


        AtomicInteger count = new AtomicInteger(0);
        System.out.println("B:" + commonLesses.size());
        List<CommonLess> eqList = new ArrayList<>();
        commonMores.forEach(more -> {
            Iterator<CommonLess> iterator = commonLesses.iterator();
            while (iterator.hasNext()) {
                CommonLess next = iterator.next();
                if (next.getKey4().equals(more.getKey4())) {
                    System.out.println(next.getKey4());
                    count.incrementAndGet();
                    eqList.add(next);
                    iterator.remove();
                }
            }
        });
        System.out.println("剩余没匹配上的:" + commonLesses.size());
        System.out.println(count);
        System.out.println("匹配上的:" + eqList.size());

        ExcelUtil.writeExcel(commonLesses, CommonLess.class, "/Users/meihongliang/Downloads/A_xiaowan/download/没有匹配上的数据_" + commonLesses.size() + ".xlsx");
        ExcelUtil.writeExcel(eqList, CommonLess.class, "/Users/meihongliang/Downloads/A_xiaowan/download/匹配上的数据_" + eqList.size() + ".xlsx");
    }
}
